<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.DriverManager" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2025/4/16
  Time: 20:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("UTF-8");
%>
<html>
<head>

    <title>Title</title>
</head>
<body>
  <%
      /**
       * 获取上一个页面传过来的参数
       */
      String stuNo = request.getParameter("stuNo");
      String stuName = request.getParameter("stuName");
      String stuSex = request.getParameter("stuSex");
      System.out.println("传过来的姓名："+stuName+"传过来的性别"+stuSex);
      /**
       * 以下代码为连接数据库代码
       */
      String dbname = "goods";//数据库名称
      String username = "root";//数据库用户名
      String password = "1234";//数据库密码
      String url =  "jdbc:mysql://localhost:3306/" +dbname;
//    Class.forName("com.mysql.jdbc.Driver");//mysql 5.7一下的版本
      Class.forName("com.mysql.cj.jdbc.Driver");//mysql 8.0
      Connection connection = DriverManager.getConnection(url,username,password);
      Statement statement = connection.createStatement();

      //执行新增语句
      int resulet = statement.executeUpdate("insert into student(stu_no,stu_name,stu_sex) values('"+stuNo+"','"+stuName+"','"+stuSex+"') ");
      if(resulet>0){//添加成功
          response.sendRedirect("search.jsp");//回到搜索页面
      }
  %>
</body>
</html>
